package com.magenta.maxoptra.geocoding.geobase.webservice;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: kuznetsovd
 * Date: 15.11.12
 * Time: 15:55
 * To change this template use File | Settings | File Templates.
 */
public class WebServicePool {

    private static Map<String, ExtendedGeoBaseWs> services = new HashMap<String, ExtendedGeoBaseWs>();

    private static WebServicePool instance;

    private static final Object sync = new Object();

    public static WebServicePool getInstance() {
        if (instance == null) {
            synchronized (sync) {
                if (instance == null) {// if instance is still null
                    instance = new WebServicePool();
                }
            }
        }
        return instance;
    }

    public ExtendedGeoBaseWs getService(final URL url) {
        ExtendedGeoBaseWs geoBaseWs = services.get(String.valueOf(url));
        if (geoBaseWs == null) {
            geoBaseWs = new ExtendedGeoBaseWs(url);
            services.put(String.valueOf(url), geoBaseWs);
        }
        return geoBaseWs;
    }


}
